package com.csg.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.csg.entity.Game;
import com.csg.service.GameService;
import com.csg.service.impl.GameServiceImpl;


@Controller
public class GameController {
//	@RequestParam before value =5 
//配置number 配置side
	//true service() 返回得到的参数值page info=page ()list   page对象集合对象分别放Model 
	//jsp首页 上一页 下一页 末页 page对象.属性  .c:foreach 
	//注入service
	@Autowired
	private GameService GameService;
	
	@RequestMapping("/selectAllGames")
	public String selectAllGames(@RequestParam(required=true,defaultValue="1")int pageNum,@RequestParam(required=true,defaultValue="5")int pageSize ,Model model){
		PageHelper.startPage(pageNum,pageSize);
		List<Game> list = this.GameService.selectAllGames();
		PageInfo<Game> page =new PageInfo<Game>(list);
		System.out.println("Controller层");
		model.addAttribute("games", list);
		model.addAttribute("page", page);
		return "forward:shouye";
//		return "/WEB-INF/main.jsp";
		
	}

	@RequestMapping("tosaveGame")
	public String tosaveGame(Integer id,Model model){
		Game game =this.GameService.selectGames(id);
		System.out.println("Controller层");
		model.addAttribute("game", game);
		
		return "/savegame.jsp";
	}
	@RequestMapping("dosaveGame")
	public String saveGame(Game game,Model model){
		
		boolean result =this.GameService.saveGame(game);
		if(result){
			return "forward:selectAllGames";
			
		}
//		return "/savepalyball.jsp";
//		return "/WEB-INF/main.jsp";
		return "forward:shouye";
	}

	
	
	@RequestMapping("/selectAllDoubleResults")
	public String selectAllDoubleResults(@RequestParam(required=true,defaultValue="1")int pageNum,@RequestParam(required=true,defaultValue="5")int pageSize ,Model model){
		PageHelper.startPage(pageNum,pageSize);
		List<Game> list = this.GameService.selectAllDoubleResults();
		PageInfo<Game> page =new PageInfo<Game>(list);
		System.out.println("Controller层");
		model.addAttribute("games", list);
		model.addAttribute("page", page);
		
		return "/doubleresultslist.jsp";
//		return "/WEB-INF/main.jsp";
		
	}
	@RequestMapping("/selectAllDoubleResults2")
	public String selectAllDoubleResults2(@RequestParam(required=true,defaultValue="1")int pageNum,@RequestParam(required=true,defaultValue="5")int pageSize ,Model model){
		PageHelper.startPage(pageNum,pageSize);
		List<Game> list = this.GameService.selectAllDoubleResults();
		PageInfo<Game> page =new PageInfo<Game>(list);
		System.out.println("Controller层");
		model.addAttribute("games", list);
		model.addAttribute("page", page);
		
		return "/doubleresultslist2.jsp";
//		return "/WEB-INF/main.jsp";
		
	}
	@RequestMapping("toupdateDoubleResult")
	public String toupdateDoubleResult(Integer id,Model model){
		
		Game game =this.GameService.selectDoubleResults(id);
		System.out.println("Controller层");
		model.addAttribute("game", game);
		return "/doubleresults.jsp";
	}
	@RequestMapping("doUpdateDoubleResult")
	public String doUpdateDoubleResult(Game game,Model model){
		
		boolean result =this.GameService.updateDoubleResult(game);
		if(result){
			return "forward:selectAllDoubleResults";
		}
		return "/doubleresults.jsp";
	}
	@RequestMapping("tosaveDoubleResult")
	public String tosaveDoubleResult(Integer id,Model model){
		Game game =this.GameService.selectDoubleResults(id);
		System.out.println("Controller层");
		model.addAttribute("game", game);
		
		return "/savedoubleresult.jsp";
	}
	@RequestMapping("dosaveDoubleResult")
	public String saveDoubleResult(Game game,Model model){
		
		boolean result =this.GameService.saveDoubleResult(game);
		if(result){
			return "forward:selectAllDoubleResults";
			
		}
//		return "/savepalyball.jsp";
		return "/doubleresultslist.jsp";
	}
	@RequestMapping("deleteDoubleResult")
	public String deleteDoubleResult(Integer id,Model model){
		
		boolean result =this.GameService.deleteDoubleResult(id);
		
		if(result){
			System.out.println("删除");
		}
		return "forward:selectAllDoubleResults";
	}
	
	
	@RequestMapping("/selectAllGoals")
	public String selectAllGoals(@RequestParam(required=true,defaultValue="1")int pageNum,@RequestParam(required=true,defaultValue="5")int pageSize ,Model model){
		PageHelper.startPage(pageNum,pageSize);
		List<Game> list = this.GameService.selectAllGoals();
		PageInfo<Game> page =new PageInfo<Game>(list);
		System.out.println("Controller层");
		model.addAttribute("games", list);
		model.addAttribute("page", page);
		return "/goalslist.jsp";
//		return "/WEB-INF/main.jsp";
		
	}
	@RequestMapping("/selectAllGoals2")
	public String selectAllGoals2(@RequestParam(required=true,defaultValue="1")int pageNum,@RequestParam(required=true,defaultValue="5")int pageSize ,Model model){
		PageHelper.startPage(pageNum,pageSize);
		List<Game> list = this.GameService.selectAllGoals();
		PageInfo<Game> page =new PageInfo<Game>(list);
		System.out.println("Controller层");
		model.addAttribute("games", list);
		model.addAttribute("page", page);
		return "/goalslist2.jsp";
//		return "/WEB-INF/main.jsp";
		
	}
	@RequestMapping("toupdateGoal")
	public String toupdateGoal(Integer id,Model model){
		
		Game game =this.GameService.selectGoals(id);
		System.out.println("Controller层");
		model.addAttribute("game", game);
		return "/goals.jsp";
	}
	@RequestMapping("doUpdateGoal")
	public String doUpdateGoal(Game game,Model model){
		
		boolean result =this.GameService.updateGoal(game);
		if(result){
			return "forward:selectAllGoals";
		}
		return "/goals.jsp";
	}
	@RequestMapping("tosaveGoal")
	public String tosaveGoal(Integer id,Model model){
		Game game =this.GameService.selectGoals(id);
		System.out.println("Controller层");
		model.addAttribute("game", game);
		
		return "/savegoal.jsp";
	}
	@RequestMapping("dosaveGoal")
	public String saveGoal(Game game,Model model){
		
		boolean result =this.GameService.saveGoal(game);
		if(result){
			return "forward:selectAllGoals";
			
		}
//		return "/savepalyball.jsp";
		return "/goalslist.jsp";
	}
	@RequestMapping("deleteGoal")
	public String deleteGoal(Integer id,Model model){
		
		boolean result =this.GameService.deleteGoal(id);
		
		if(result){
			System.out.println("删除");
		}
		return "forward:selectAllGoals";
	}
	
	
	
	@RequestMapping("/selectAllPalyBalls")
	public String selectAllPalyBalls(@RequestParam(required=true,defaultValue="1")int pageNum,@RequestParam(required=true,defaultValue="5")int pageSize ,Model model){
		PageHelper.startPage(pageNum,pageSize);
		List<Game> list = this.GameService.selectAllPalyBalls();
		PageInfo<Game> page =new PageInfo<Game>(list);
		System.out.println("Controller层");
		model.addAttribute("games", list);
		model.addAttribute("page", page);
		return "/palyballslist.jsp";
//		return "/WEB-INF/main.jsp";
		
	}
	@RequestMapping("/selectAllPalyBalls2")
	public String selectAllPalyBalls2(@RequestParam(required=true,defaultValue="1")int pageNum,@RequestParam(required=true,defaultValue="5")int pageSize ,Model model){
		PageHelper.startPage(pageNum,pageSize);
		List<Game> list = this.GameService.selectAllPalyBalls();
		PageInfo<Game> page =new PageInfo<Game>(list);
		System.out.println("Controller层");
		model.addAttribute("games", list);
		model.addAttribute("page", page);
		return "/palyballslist2.jsp";
//		return "/WEB-INF/main.jsp";
		
	}
	@RequestMapping("toupdatePalyBall")
	public String toupdatePalyBall(Integer id,Model model){
		
		Game game =this.GameService.selectPalyBalls(id);
		System.out.println("Controller层");
		model.addAttribute("game", game);
		return "/palyballs.jsp";
	}
	@RequestMapping("doUpdatePalyBall")
	public String doUpdatePalyBall(Game game,Model model){
		
		boolean result =this.GameService.updatePalyBall(game);
		if(result){
			return "forward:selectAllPalyBalls";
		}
		return "/palyballs.jsp";
	}
	@RequestMapping("tosavePalyBall")
	public String tosavePalyBall(Integer id,Model model){
		Game game =this.GameService.selectPalyBalls(id);
		System.out.println("Controller层");
		model.addAttribute("game", game);
		
		return "/savepalyball.jsp";
	}
	@RequestMapping("dosavePalyBall")
	public String savePalyBall(Game game,Model model){
		
		boolean result =this.GameService.savePalyBall(game);
		if(result){
			return "forward:selectAllPalyBalls";
			
		}
//		return "/savepalyball.jsp";
		return "/palyballslist.jsp";
	}
	@RequestMapping("deletePalyBall")
	public String deletePalyBall(Integer id,Model model){
		
		boolean result =this.GameService.deletePalyBall(id);
		
		if(result){
			System.out.println("删除");
		}
		return "forward:selectAllPalyBalls";
	}
	
	
	
	@RequestMapping("/selectAllPasss")
	public String selectAllPasss(@RequestParam(required=true,defaultValue="1")int pageNum,@RequestParam(required=true,defaultValue="5")int pageSize ,Model model){
		PageHelper.startPage(pageNum,pageSize);
		List<Game> list = this.GameService.selectAllPasss();
		PageInfo<Game> page =new PageInfo<Game>(list);
		System.out.println("Controller层");
		model.addAttribute("games", list);
		model.addAttribute("page", page);
		return "/passlist.jsp";
//		return "/WEB-INF/main.jsp";
		
	}
	@RequestMapping("/selectAllPasss2")
	public String selectAllPasss2(@RequestParam(required=true,defaultValue="1")int pageNum,@RequestParam(required=true,defaultValue="5")int pageSize ,Model model){
		PageHelper.startPage(pageNum,pageSize);
		List<Game> list = this.GameService.selectAllPasss();
		PageInfo<Game> page =new PageInfo<Game>(list);
		System.out.println("Controller层");
		model.addAttribute("games", list);
		model.addAttribute("page", page);
		return "/passlist2.jsp";
//		return "/WEB-INF/main.jsp";
		
	}
	@RequestMapping("toupdatePass")
	public String toupdatePass(Integer id,Model model){
		
		Game game =this.GameService.selectPasss(id);
		System.out.println("Controller层");
		model.addAttribute("game", game);
		return "/pass.jsp";
	}
	@RequestMapping("doUpdatePass")
	public String doUpdatePass(Game game,Model model){
		
		boolean result =this.GameService.updatePass(game);
		if(result){
			return "forward:selectAllPasss";
		}
		return "/pass.jsp";
	}
	@RequestMapping("tosavePass")
	public String tosavePass(Integer id,Model model){
		Game game =this.GameService.selectPasss(id);
		System.out.println("Controller层");
		model.addAttribute("game", game);
		
		return "/savepass.jsp";
	}
	@RequestMapping("dosavePass")
	public String savePass(Game game,Model model){
		
		boolean result =this.GameService.savePass(game);
		if(result){
			return "forward:selectAllPasss";
			
		}
//		return "/savepalyball.jsp";
		return "/passlist.jsp";
	}
	@RequestMapping("deletePass")
	public String deletePass(Integer id,Model model){
		
		boolean result =this.GameService.deletePass(id);
		
		if(result){
			System.out.println("删除");
		}
		return "forward:selectAllPasss";
	}
	
	
	
	@RequestMapping("/selectAllScores")
	public String selectAllScores(@RequestParam(required=true,defaultValue="1")int pageNum,@RequestParam(required=true,defaultValue="5")int pageSize ,Model model){
		PageHelper.startPage(pageNum,pageSize);
		List<Game> list = this.GameService.selectAllScores();
		PageInfo<Game> page =new PageInfo<Game>(list);
		System.out.println("Controller层");
		model.addAttribute("games", list);
		model.addAttribute("page", page);
		return "/scoreslist.jsp";
//		return "/WEB-INF/main.jsp";
		
	}
	@RequestMapping("/selectAllScores2")
	public String selectAllScores2(@RequestParam(required=true,defaultValue="1")int pageNum,@RequestParam(required=true,defaultValue="5")int pageSize ,Model model){
		PageHelper.startPage(pageNum,pageSize);
		List<Game> list = this.GameService.selectAllScores();
		PageInfo<Game> page =new PageInfo<Game>(list);
		System.out.println("Controller层");
		model.addAttribute("games", list);
		model.addAttribute("page", page);
		return "/scoreslist2.jsp";
//		return "/WEB-INF/main.jsp";
		
	}
	@RequestMapping("toupdateScore")
	public String toupdateScore(Integer id,Model model){
		
		Game game =this.GameService.selectScores(id);
		System.out.println("Controller层");
		model.addAttribute("game", game);
		return "/scores.jsp";
	}
	@RequestMapping("doUpdateScore")
	public String doUpdateScore(Game game,Model model){
		
		boolean result =this.GameService.updateScore(game);
		if(result){
			return "forward:selectAllScores";
		}
		return "/scores.jsp";
	}
	@RequestMapping("tosaveScore")
	public String tosaveScore(Integer id,Model model){
		Game game =this.GameService.selectScores(id);
		System.out.println("Controller层");
		model.addAttribute("game", game);
		
		return "/savescore.jsp";
	}
	@RequestMapping("dosaveScore")
	public String saveScore(Game game,Model model){
		
		boolean result =this.GameService.saveScore(game);
		if(result){
			return "forward:selectAllScores";
			
		}
//		return "/savepalyball.jsp";
		return "/scoreslist.jsp";
	}
	@RequestMapping("deleteScore")
	public String deleteScore(Integer id,Model model){
		
		boolean result =this.GameService.deleteScore(id);
		
		if(result){
			System.out.println("删除");
		}
		return "forward:selectAllScores";
	}
	
	
	
	
}
